<?php
require_cache(COMMON_PATH.'interface.php');
function getEditionName($id){
	$info = D('Edition')->where('id='.$id)->field('title')->find();
	if($info['title']){
		return $info['title'];
	}else{
		return '未指定';
	}
}

function getCategoryName($id){
	$info = D('Category')->where('id='.$id)->field('title')->find();
	if($info['title']){
		return $info['title'];
	}else{
		return '未指定';
	}
}

function getStateInfo($state='list'){
	$list = array(
		'0' => '待处理',
		'1' => '已指派',
		'2' => '处理中',
		'3' => '已解决',
		'4' => '已关闭',
	);
	if($state!='list'){
		return $list[$state];
	}else{
		return $list;
	}
}

function getStateColor($state){
	switch ($state){
		case '0':
			$color="red";
		break;
		
		case '3':
		case '4':	
			$color="green";
		break;
		default:
			$color = 'blue';
		break;
	}
	return $color;
}

//加红标题
function red($string, $words, $color = 'red', $strlen = 0)
{
	if($string == '' || $words == '') return '';
	$position = $search = $replace = array();
	if(!is_array($words)) $words = explode(' ', $words);
	foreach($words as $k=>$word)
	{
		$pos = strpos($string, $word);
		if($pos === false) continue;
		$search[$k] = $word;
		$replace[$k] = '<font color="'.$color.'">'.$word.'</font>';
		if($k == 2) break;
	}
	if($strlen) $string = msubstr($string, $strlen);
	return str_replace($search, $replace, $string);
}

function getStateCount($isall='false',$n){
	if ($isall=='true') {
		return D('Bug')->count();
	}else{
		$map['state'] = intval($n);
		return D('Bug')->where($map)->count();
	}
}

